import { ajax } from '../http.js';

const wxAuthorizationUrl = '/mp_authorization_login';
const wxAuthorizationLoginUrl = '/weixin/authorization_login_url';
const loginByPasswordUrl = '/login_by_password';
const loginByCodeUrl = '/mobile_code_login';
const resetPwdByCodeUrl = '/reset_pwd_by_code';
const wxBindPhoneUrl = '/binding_wx_and_mobile'; // 微信绑定手机号
const getAlipayAuthLoginUrl = '/alipay_auth_login_url'; // 获取支付宝授权登录地址
const loginInAlipayUrl = '/alipay_auth_login'; // 支付宝登录
const alipayBindPhoneUrl = '/binding_alipay_and_mobile'; // 支付宝绑定手机号

const alipayBindPhoneApi = (data, success, fail, opt) => ajax({ // 支付宝登录
  noAuth: true,
  url: alipayBindPhoneUrl,
  data: data,
  success: success,
  fail: fail,
  opt: opt
});

const loginInAlipayApi = (data, success, fail, opt) => ajax({ // 支付宝登录
  noAuth: true,
  url: loginInAlipayUrl,
  data: data,
  success: success,
  fail: fail,
  opt: opt
});

const getAlipayAuthLoginApi = (data, success, fail, opt) => ajax({ // 获取支付宝授权登录地址
  noAuth: true,
  url: getAlipayAuthLoginUrl,
  data: data,
  success: success,
  fail: fail,
  opt: opt
});

const wxBindPhoneApi = (data, success, fail, opt) => ajax({ // 微信绑定手机号
  noAuth: true,
  url: wxBindPhoneUrl,
  data: data,
  success: success,
  fail: fail,
  opt: opt
});

// 微信公众号授权
const wxAuthorization = (data, success, fail) => ajax({
  noAuth: true,
  url: wxAuthorizationUrl,
  data: data,
  success: success,
  fail: fail
});

// 获取授权地址
const wxAuthorizationLogin = (data, success, fail) => ajax({
  noAuth: true,
  data: data,
  url: wxAuthorizationLoginUrl,
  success: success,
  fail: fail
});

// 手机号密码登录
const loginByPassword = (data, success, fail) => {
  ajax({
    noAuth: true,
    url: loginByPasswordUrl,
    data: data,
    success: success,
    fail: fail
  });
};

// 短信验证码登录
const loginByCode = (data, success, fail) => {
  ajax({
    noAuth: true,
    url: loginByCodeUrl,
    data: data,
    success: success,
    fail: fail
  });
};

const resetPwdByCode = (data, success, fail) => {
  ajax({
    noAuth: true,
    url: resetPwdByCodeUrl,
    data: data,
    success: success,
    fail: fail
  });
};

export {
  wxAuthorization,
  wxAuthorizationLogin,
  loginByPassword,
  loginByCode,
  resetPwdByCode,
  wxBindPhoneApi,
  getAlipayAuthLoginApi,
  loginInAlipayApi,
  alipayBindPhoneApi
}